package com.huizhonglm.diap.presenters.tab;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.model.user.MarketDefaultParams;
import com.huizhonglm.diap.api.model.user.MarketInfo;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.tab.iView.TabhostMarketIView;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:53
 */
public class TabhostMarketPresenter extends BasePresenter {

    private TabhostMarketIView iView;

    public TabhostMarketPresenter(TabhostMarketIView iView) {
        this.iView = iView;
    }

    public void loadData(String userId){
        MarketDefaultParams params = new MarketDefaultParams();
        params.uid = userId;


        API.http().post("point_shop", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    MarketInfo data = JSON.parseObject(result, MarketInfo.class);
                    if (data!=null) {
                        iView.onLoadDataSuccess( data);
                    } else {
                        iView.onLoadDataEmpty();
                    }
                } else {
                    iView.onLoadDataEmpty();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onLoadDataFailure();
            }
        });
    }
}
